#  数据库相关
from db.redis import StrictRedis
from settings.settinglod import Setting  # 标准setting类


# 创建一个redis的数据,返回可redis对象
class RedisOperator(object):
    "与redis有关的操作，不阻塞"

    def __init__(self, setting: Setting):
        self.pro = setting.__dict__.get("pro_name", "databases")
        self.host = setting.__dict__.get("redis:host", "127.0.0.1")
        self.password = setting.__dict__.get("redis:password", None)
        self.port = setting.__dict__.get("redis:port", "6379")
        self.db = setting.__dict__.get("redis:db", 0)
        self.conn = StrictRedis(host=self.host, password=self.password, db=self.db, port=self.port)  # 链接

    def get(self):
        "拿数据"
        return self.conn.rpop(self.pro)  # 返回数据

    def put(self, data: str):
        return self.conn.lpush(self.pro, data)  # 添加数据

    def execute(self, *args):
        return self.conn  # 其他命令
